import {
  ExtrudeGeometry,
  MeshBasicMaterial,
  Vector3,
  BufferGeometry,
  EdgesGeometry,
  LineBasicMaterial,
  LineSegments,
  Mesh,
  type ColorRepresentation,
} from "three";
import { Part3DMesh } from "../types/DrawingGroups/meshs";
import { KujialeParamModel } from "../types/KujialeJsonModels/KujialeParamModel";
import { DrawPathShape } from "./path";
import { PartModel } from "../types/Models";
import { type DrawContext } from "./context";
import { DrawMeshWireframeLines } from "./wireframe";

export const DrawPart3DMesh = (
  json: KujialeParamModel,
  context: DrawContext
): Mesh | undefined => {
  const mesh = new Part3DMesh(new PartModel(json));
  const shape = DrawPathShape(json);
  const setting = { step: 3, depth: json.thickness };
  mesh.geometry = new ExtrudeGeometry(shape, setting);
  mesh.material = new MeshBasicMaterial({
    color: context.colors[json.textureName],
  });
  mesh.rotateOnWorldAxis(new Vector3(1, 0, 0), -Math.PI / 2);
  mesh.rotateAndMoveByPartModel();
  DrawMeshWireframeLines(mesh, true, context.colors["wireframe"]);
  return mesh;
};
